package com.factors.ZhangDingHou.Income;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class ExamScoreMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

    private final static IntWritable examScore = new IntWritable();
    private Text familyIncome = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        if (key.get() == 0) return;

        String[] columns = value.toString().split(",");
        if (columns.length >= 20) {
            String familyIncomeStr = columns[10];
            String examScoreStr = columns[19];

            try {
                int score = Integer.parseInt(examScoreStr);
                familyIncome.set(familyIncomeStr);
                examScore.set(score);
                context.write(familyIncome, examScore);
            } catch (NumberFormatException e) {

            }
        }
    }
}